package org.hit.burkun.cases.pipline;

import org.hit.burkun.cases.mapping.HgncImport;
import org.hit.burkun.cases.mapping.ImportStringGeneIDMapping;
import org.hit.burkun.db.DBHelper;
import org.hit.burkun.db.DBTypeConverter;
import org.hit.burkun.db.DBTypeConverter.DATATYPE;
import org.hit.burkun.dbimport.FileBaseImport;
import org.hit.burkun.dbimport.FileBaseImport.LINE_SPLITER;
import org.hit.burkun.file.FileProcessHelper.FILE_TYPE;
import org.hit.burkun.obo.dbimport.BaseImport;
import org.hit.burkun.obo.dbimport.OboTable.ONTOLOGYNAME;
import org.hit.burkun.util.GlobalData;

public class TotalPipe {

	public static void main(String[] args) {
		// -- step 1
		// ---mapping
		// importStringMapping();
		// importHgnc();
		// ---mapping
		// ---data
		// importStringData();
		// importDO();
		// importGO();
		// importHPO();
		// importHpGene();
		// importGeneInfo();
		// importCtdGenesDiseases();
		// importOmim2gene();
		 importMorbidMap();
		// importHpoAnnotation();
		//importHPGene();
		// importGoaHuman();
		// ---data
		// --step 1
		//step 2
	}

	// ---step 1 mapping
	public static void importStringMapping() {
		ImportStringGeneIDMapping importer = new ImportStringGeneIDMapping(
				GlobalData.getInstance().getStringGeneIdPath(),
				"dbkey_mapping", DBHelper.getLocalBioSearch());
		importer.doImport();
	}

	public static void importHgnc() {
		String fileName = GlobalData.getInstance().getHgncPath();
		final DBHelper dbHelper = DBHelper.getLocalBioSearch();
		int totalPropertyNum = 48;
		FILE_TYPE fileType = FILE_TYPE.GZIP;
		String tableName = "hgnc_complete_set";
		int beginLineNum = 2;
		boolean hasAutoIncreasementID = false;
		LINE_SPLITER spliterType = LINE_SPLITER.TAB;

		DBTypeConverter.DATATYPE[] types = new DBTypeConverter.DATATYPE[totalPropertyNum];
		types[18] = DBTypeConverter.DATATYPE.I;
		DBTypeConverter typeConverter = new DBTypeConverter(types);
		HgncImport imp = new HgncImport(fileName, fileType, tableName,
				dbHelper, totalPropertyNum, hasAutoIncreasementID,
				typeConverter, spliterType);
		imp.setBatchImportNumber(1000);
		imp.doImport(beginLineNum);
	}

	// ---end step 1 mapping

	// --- step 1 relations & entity
	public static void importStringData() {
		String proteinPath = GlobalData.getInstance()
				.getStringInteractionPath();
		final DBHelper dbHelper = DBHelper.getLocalBioSearch();
		int totalPropertyNum = 14;
		FILE_TYPE fileType = FILE_TYPE.GZIP;
		String tableName = "string_interactions_combine";
		int beginLine = 2;
		boolean hasAutoIncreasementID = true;
		LINE_SPLITER spliterType = LINE_SPLITER.SPACE;

		DBTypeConverter.DATATYPE[] types = new DBTypeConverter.DATATYPE[totalPropertyNum];
		types[0] = DATATYPE.I;
		types[5] = DATATYPE.D;
		types[6] = DATATYPE.D;
		types[7] = DATATYPE.D;
		types[8] = DATATYPE.D;
		types[9] = DATATYPE.D;
		types[10] = DATATYPE.D;
		types[11] = DATATYPE.D;
		types[12] = DATATYPE.D;
		DBTypeConverter typeConverter = new DBTypeConverter(types);
		FileBaseImport imp = new StringInteractionImport(proteinPath, fileType,
				tableName, dbHelper, totalPropertyNum, hasAutoIncreasementID,
				typeConverter, spliterType);
		imp.setBatchImportNumber(10000);
		imp.doImport(beginLine);
	}

	public static void importGO() {
		DBHelper dbHelper = DBHelper.getLocalBioSearch();
		String path = GlobalData.getInstance().getGOPath();
		BaseImport im = new BaseImport(path, dbHelper, ONTOLOGYNAME.GO, 1000);
		im.importAll();
	}

	public static void importDO() {
		// DBHelper dbHelper = new DBHelper("219.223.244.255", "biosearch",
		// "root", "bureaucrat", false);
		DBHelper dbHelper = DBHelper.getLocalBioSearch();
		String path = GlobalData.getInstance().getDOPath();

		BaseImport im = new BaseImport(path, dbHelper, ONTOLOGYNAME.DO, 1000);
		im.importAll();
	}

	public static void importHPO() {
		DBHelper dbHelper = DBHelper.getLocalBioSearch();
		String path = GlobalData.getInstance().getHPOPath();
		BaseImport im = new BaseImport(path, dbHelper, ONTOLOGYNAME.HPO, 1000);
		im.importAll();
	}

	public static void importHpGene() {
		String fileName = GlobalData.getInstance().getHpGenePath();
		final DBHelper dbHelper = DBHelper.getLocalBioSearch();
		int totalPropertyNum = 5;
		FILE_TYPE fileType = FILE_TYPE.PLAIN;
		String tableName = "hp_gene";
		int beginLineNum = 2;
		boolean hasAutoIncreasementID = true;
		LINE_SPLITER spliterType = LINE_SPLITER.TAB;

		DBTypeConverter.DATATYPE[] types = new DBTypeConverter.DATATYPE[totalPropertyNum];
		types[0] = DBTypeConverter.DATATYPE.I;
		types[3] = DBTypeConverter.DATATYPE.I;
		DBTypeConverter typeConverter = new DBTypeConverter(types);
		FileBaseImport imp = new FileBaseImport(fileName, fileType, tableName,
				dbHelper, totalPropertyNum, hasAutoIncreasementID,
				typeConverter, spliterType);
		imp.setBatchImportNumber(1000);
		imp.doImport(beginLineNum);
	}

	public static void importGoaHuman() {
		String fileName = GlobalData.getInstance().getGoaPath();
		DBHelper dbHelper = DBHelper.getLocalBioSearch();
		int totalPropertyNum = 18;
		FILE_TYPE fileType = FILE_TYPE.GZIP;
		// String tableName = "goa_ref_human";
		String tableName = "go_annotation_human";
		int beginLineNum = 35;
		boolean hasAutoIncreasementID = true;
		LINE_SPLITER spliterType = LINE_SPLITER.TAB;

		DBTypeConverter.DATATYPE[] types = new DBTypeConverter.DATATYPE[totalPropertyNum];
		types[0] = DBTypeConverter.DATATYPE.I;

		DBTypeConverter typeConverter = new DBTypeConverter(types);
		FileBaseImport imp = new FileBaseImport(fileName, fileType, tableName,
				dbHelper, totalPropertyNum, hasAutoIncreasementID,
				typeConverter, spliterType);

		imp.doImport(beginLineNum);
	}

	public static void importOmim2gene() {
		OMIMImport.importOmim2gene();
	}

	public static void importCtdGenesDiseases() {
		String fileName = GlobalData.getInstance().getCtdGeneDisease();
		final DBHelper dbHelper = DBHelper.getLocalBioSearch();
		int totalPropertyNum = 10;
		FILE_TYPE fileType = FILE_TYPE.GZIP;
		String tableName = "ctd_genes_diseases";
		String commentString = "#";
		boolean hasAutoIncreasementID = true;
		LINE_SPLITER spliterType = LINE_SPLITER.COMMA;

		DBTypeConverter.DATATYPE[] types = new DBTypeConverter.DATATYPE[totalPropertyNum];
		types[0] = DBTypeConverter.DATATYPE.I;
		types[2] = DBTypeConverter.DATATYPE.I;
		types[7] = DBTypeConverter.DATATYPE.D;

		DBTypeConverter typeConverter = new DBTypeConverter(types);
		FileBaseImport imp = new FileBaseImport(fileName, fileType, tableName,
				dbHelper, totalPropertyNum, hasAutoIncreasementID,
				typeConverter, spliterType);
		imp.setBatchImportNumber(30000);
		imp.doImport(commentString);
	}

	public static void importGeneInfo() {
		String fileName = GlobalData.getInstance().getGeneTermPath();
		final DBHelper dbHelper = DBHelper.getLocalBioSearch();
		int totalPropertyNum = 16;
		FILE_TYPE fileType = FILE_TYPE.PLAIN;
		String tableName = "gene_term";
		int beginLine = 2;
		boolean hasAutoIncreasementID = true;
		LINE_SPLITER spliterType = LINE_SPLITER.TAB;

		DBTypeConverter.DATATYPE[] types = new DBTypeConverter.DATATYPE[totalPropertyNum];
		types[0] = DBTypeConverter.DATATYPE.I;
		types[1] = DBTypeConverter.DATATYPE.I;
		types[2] = DBTypeConverter.DATATYPE.I;

		DBTypeConverter typeConverter = new DBTypeConverter(types);
		GeneTermImport imp = new GeneTermImport(fileName, fileType, tableName,
				dbHelper, totalPropertyNum, hasAutoIncreasementID,
				typeConverter, spliterType);

		imp.doImport(beginLine);
	}

	public static void importMorbidMap() {
		//OMIMMorbidmapImport.importMorbidMap();
		OMIMMorbidmapImport.importMorbidMapNew();
	}

	public static void importHpoAnnotation() {
		// annotation http links
		// http://www.human-phenotype-ontology.org/contao/index.php/annotation-guide.html
		String fileName = GlobalData.getInstance().getHpoAnnotationPath();
		final DBHelper dbHelper = DBHelper.getLocalBioSearch();
		int totalPropertyNum = 14;
		FILE_TYPE fileType = FILE_TYPE.PLAIN;
		String tableName = "hp_annotation";
		int beginLineNum = 1;
		boolean hasAutoIncreasementID = false;
		LINE_SPLITER spliterType = LINE_SPLITER.TAB;

		DBTypeConverter.DATATYPE[] types = new DBTypeConverter.DATATYPE[totalPropertyNum];

		DBTypeConverter typeConverter = new DBTypeConverter(types);
		FileBaseImport imp = new HPOAImport(fileName, fileType, tableName,
				dbHelper, totalPropertyNum, hasAutoIncreasementID,
				typeConverter, spliterType);

		imp.doImport(beginLineNum);
	}

	public static void importHPGene() {
		String fileName = GlobalData.getInstance().getHPOPath();
		final DBHelper dbHelper = DBHelper.getLocalBioSearch();
		int totalPropertyNum = 5;
		FILE_TYPE fileType = FILE_TYPE.PLAIN;
		String tableName = "hp_gene";
		int beginLineNum = 2;
		boolean hasAutoIncreasementID = true;
		LINE_SPLITER spliterType = LINE_SPLITER.TAB;

		DBTypeConverter.DATATYPE[] types = new DBTypeConverter.DATATYPE[totalPropertyNum];
		types[0] = DBTypeConverter.DATATYPE.I;
		types[3] = DBTypeConverter.DATATYPE.I;
		DBTypeConverter typeConverter = new DBTypeConverter(types);
		FileBaseImport imp = new FileBaseImport(fileName, fileType, tableName,
				dbHelper, totalPropertyNum, hasAutoIncreasementID,
				typeConverter, spliterType);
		imp.setBatchImportNumber(1000);
		imp.doImport(beginLineNum);
	}
	// --- end step 1 relations
}
